package powtorka.serializacja;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.text.DateFormat;
import java.util.Date;

public class DrugaSerializacja {

	public static void main(String[] args) {

		int a = 7;
		String napis = "Ala ma kota.";
		Date data = new Date();
		Integer aObj = new Integer(a);
		
		File plik = new File("plikZapisowy.ser");
		
		try {
			ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(plik));
			os.writeObject(napis);
			os.writeObject(data);
			os.writeObject(aObj);
			os.close();
		} catch (FileNotFoundException e) {
			System.out.println("Nie znaleziono pliku");
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		try {
			ObjectInputStream is = new ObjectInputStream(new FileInputStream(plik));
			System.out.println((String) is.readObject());
			System.out.println(DateFormat.getDateInstance().format((Date) is.readObject()));
			System.out.println(((Integer) is.readObject()).intValue());
			is.close();
		} catch (FileNotFoundException e) {
			System.out.println("Nie odnaleziono pliku");
		} catch (IOException e) {
		} catch (ClassNotFoundException e) {
		}
		
	}

}
